package com.marlowe.asyouknow.controller;

import com.marlowe.asyouknow.service.PicturesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @program: as-you-know
 * @description: 图片controller
 * @author: Marlowe
 * @create: 2020-12-22 16:58
 **/
@Api(tags = "图片搜索控制类")
@RestController
public class PicturesController {
    @Autowired
    private PicturesService picturesService;

    @ApiOperation(value = "百度图库图片检索")
    @GetMapping("/pictures/{keyword}/{pageNo}/{pageSize}")
    public List<Map<String, Object>> search(@PathVariable("keyword") String keyword,
                                            @PathVariable("pageNo") int pageNo,
                                            @PathVariable("pageSize") int pageSize) throws IOException {

        return picturesService.searchPageHighlightBuilder(keyword, pageNo, pageSize);
    }

    @ApiOperation(value = "百度图库检索提示")
    @GetMapping("/pictures/{keyword}")
    public List<Map<String, Object>> search(@PathVariable("keyword") String keyword) throws IOException {
        return picturesService.searchSuggestion(keyword);
    }
}
